//
//  SLRecommandViewController.m
//  SoccerLottery
//
//  Created by chuanshuangzhang chuan shuang on 15/12/24.
//  Copyright © 2015年 chuanshuangzhang. All rights reserved.
//

#import "SLRecommandViewController.h"

@interface SLRecommandViewController ()<UIWebViewDelegate>

@end

@implementation SLRecommandViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _scrollView = [[UIScrollView alloc]init];
    _scrollView.frame = self.view.bounds;
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    _topView = [[UIView alloc]init];
    _topView.frame = CGRectMake(0, 0, App_Frame_Width, App_Frame_Width*0.445);
    _topView.backgroundColor = RGBACOLOR(14, 107, 92, 1.0);
    [_scrollView addSubview:_topView];
    
    _topImageView = [[UIImageView alloc]init];
    UIImage *image = [UIImage imageNamed:@"portrait"];
    _topImageView.image = image;
    _topImageView.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
    _topImageView.center = CGPointMake(App_Frame_Width*0.5, _topView.height/2.0-10);
    if(IPHONE4S|| IPHONE5){
        _topImageView.transform = CGAffineTransformMakeScale(0.8, 0.8);
    }
    [_topView addSubview:_topImageView];
    
    _topLabel = [[UILabel alloc]init];
    _topLabel.text = @"足彩购买指南";
    _topLabel.frame = CGRectMake(0, _topImageView.bottom+5, _topView.width, 20);
    _topLabel.font = [UIFont fontWithName:@"Arial" size:14];
    _topLabel.textColor = [UIColor blackColor];
    _topLabel.textAlignment = NSTextAlignmentCenter;
    [_topView addSubview:_topLabel];
    
    _midView = [[UIView alloc]init];
    [_scrollView addSubview:_midView];
    
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = [UIFont fontWithName:@"Arial" size:16];
    _titleLabel.textColor = [UIColor blackColor];
    [_midView addSubview:_titleLabel];
    [_titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
    [_midView addConstraint:[NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_midView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:5]];
    
    
    _timeLabel = [[UILabel alloc]init];
    _timeLabel.font = [UIFont fontWithName:@"Arial" size:14];
    _timeLabel.textColor = [UIColor grayColor];
    [_midView addSubview:_timeLabel];
    [_timeLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
    [_midView addConstraint:[NSLayoutConstraint constraintWithItem:_timeLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_midView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:5]];
    
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = RGBACOLOR(226, 226, 226, 1.0);
    [_midView addSubview:lineView];
    [lineView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [_midView addConstraint:[NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_midView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]];
    [_midView addConstraint:[NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_midView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]];
    [_midView addConstraint:[NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_midView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-0.5]];
    [_midView addConstraint:[NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:_midView attribute:NSLayoutAttributeHeight multiplier:0.0 constant:0.5]];
    
    _webView = [[UIWebView alloc]init];
    _webView.userInteractionEnabled = NO;
    _webView.delegate = self;

    [_webView loadHTMLString:self.feedModel.detail baseURL:nil];
    [_scrollView addSubview:_webView];
    
    _titleLabel.text = self.feedModel.title;
    _timeLabel.text = self.feedModel.time;
    
    // Do any additional setup after loading the view.
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGSize actualSize = [webView sizeThatFits:CGSizeZero];
    CGRect newFrame = webView.frame;
    newFrame.size.height = actualSize.height;
    webView.frame = newFrame;
    _scrollView.contentSize = CGSizeMake(App_Frame_Width, self.midView.bottom+newFrame.size.height+64);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
